package com.vmj.instructions.math;

import com.vmj.common.BytesReader;
import com.vmj.instructions.base.NoOperandsInstruction;
import com.vmj.rtda.Frame;
import com.vmj.rtda.LocalVars;

/**
 * Created by yangshoujun on 2017/8/19 下午10:59.
 */
public class IInc extends NoOperandsInstruction {

    int index;
    int constant;

    @Override
    public void fetchOperands(BytesReader reader) {
        index = reader.readByte();
        constant = reader.readByte();
    }

    @Override
    public void execute(Frame frame) {
        LocalVars localVars = frame.getLocalVars();
        int value = localVars.getInt(index);
        value += constant;
        localVars.setInt(index, value);
    }

    public int getIndex() {
        return index;
    }

    public int getConstant() {
        return constant;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public void setConstant(int constant) {
        this.constant = constant;
    }
}
